package com.firstcare.android_dylibrary_demo.Main;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSONObject;
import com.android.volley.VolleyError;
import com.firstcare.android_dylibrary.bean.Account;
import com.firstcare.android_dylibrary.bean.AccountProxy;
import com.firstcare.android_dylibrary.bean.HomeProxy;
import com.firstcare.android_dylibrary_demo.DYApp;
import com.firstcare.android_dylibrary_demo.R;
import com.rdxer.xxlibrary.HTTPUtils.error.ProcessingError;
import com.rdxer.xxlibrary.HTTPUtils.listener.ErrorListener;
import com.rdxer.xxlibrary.HTTPUtils.listener.FailedListener;
import com.rdxer.xxlibrary.HTTPUtils.listener.OKListener;
import com.rdxer.xxlibrary.base.BaseActivity;
import com.rdxer.xxlibrary.utils.Log;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends BaseActivity {

    @BindView(R.id.textView)
    TextView textView;
    @BindView(R.id.button_test)
    Button buttonTest;
    @BindView(R.id.button)
    Button button;
    @BindView(R.id.button2)
    Button button2;
    @BindView(R.id.button3)
    Button button3;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        // 获取参数
        // 请确保前面也是同种类型
        AccountProxy accountProxy = getActivityParames();

    }

    public void testClick() {
        HomeProxy.getHomeProxyList(new OKListener<List<HomeProxy>>() {
            @Override
            public void onOK(List<HomeProxy> res, JSONObject response) {
                Toast.makeText(MainActivity.this, "" + res + response, Toast.LENGTH_SHORT).show();
            }
        }, new FailedListener() {
            @Override
            public void onFailed(ProcessingError error) {
                Toast.makeText(MainActivity.this, "" + error.getMessage() + error.getDetailsMessage(), Toast.LENGTH_SHORT).show();
            }
        }, new ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(MainActivity.this, "" + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    @OnClick({R.id.button_test, R.id.button, R.id.button2, R.id.button3})
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.button_test:

                long  lo = DYApp.getShared().getAccountProxy().saveToDB();
                Toast.makeText(MainActivity.this, ""+lo, Toast.LENGTH_SHORT).show();

                break;
            case R.id.button:

                ArrayList<Account> a = AccountProxy.queryDB();
                Toast.makeText(MainActivity.this, ""+a, Toast.LENGTH_SHORT).show();

                break;
            case R.id.button2:
//                Toast.makeText(MainActivity.this, ""+ UUID.randomUUID(), Toast.LENGTH_SHORT).show();

                break;
            case R.id.button3:
                setResult(100,new Account("zhangsan","adasdasdasdassd"));
                finish();
                break;
        }
    }
}
